﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using FrienDev;
using FrienDev.BusinessRules;

public partial class Controls_Activity_List : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack && !IsReload)
            return;
        IsReload = false;
        pnSubNavigateBar.Visible = IsFriend ? false : true;
        if (IsOutOfDate && !IsFriend)
        {
            lbOldActivity_Click(null, null);
        }
        else if (!IsOutOfDate && !IsFriend)
        {
            lbRecentActivity_Click(null, null);
        }

        if (IsFriend && IsPaging == false)
        {
            ActivityGrid.EmptyDataText = "好友没有活动";
            ActivityGrid.DataSource = ActivityRules.Instance.GetFriendsActivities(UserRules.Instance.GetCurrentUserId());
            ActivityGrid.AllowPaging = false;
            ActivityGrid.DataBind();
            
            upGridView.Update();
        }

        if (IsFriend && IsPaging)
        {
            ActivityGrid.EmptyDataText = "好友没有活动";
            if (ActivityRules.Instance.GetFriendsActivities(UserRules.Instance.GetCurrentUserId()) != null)
            {
                ActivityGrid.DataSource = ActivityRules.Instance.GetFriendsActivities(UserRules.Instance.GetCurrentUserId());
                ActivityGrid.AllowPaging = true;
                ActivityGrid.Columns[6].Visible = true;
                ActivityGrid.Columns[7].Visible = true;
                ActivityGrid.DataBind();
            }
            
            upGridView.Update();
        }

    }

    protected void lbRecentActivity_Click(object sender, EventArgs e)
    {
        ActivityGrid.EmptyDataText = "没有近期活动";
        ActivityGrid.DataSource = ActivityRules.Instance.GetUserRecentActivities(UserRules.Instance.GetCurrentUserId());
        ActivityGrid.AllowPaging = false;
        ActivityGrid.DataBind();
        
        upGridView.Update();
    }

    protected void lbOldActivity_Click(object sender, EventArgs e)
    {
        ActivityGrid.EmptyDataText = "没有过期活动";
        if (ActivityRules.Instance.GetUserOldActivites(UserRules.Instance.GetCurrentUserId()) != null)
        {
            ActivityGrid.DataSource = ActivityRules.Instance.GetUserOldActivites(UserRules.Instance.GetCurrentUserId());
            ActivityGrid.AllowPaging = false;
            ActivityGrid.DataBind();
        }
        
        upGridView.Update();
    }

    protected void ActivityGrid_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label temp_lbActivityState = e.Row.FindControl("lbl_ActivityState") as Label;
            Label temp_lblPostsCount = e.Row.FindControl("lbl_PostsCount") as Label;
            Label temp_txtBeginDateTime = e.Row.FindControl("txt_BeginDateTime") as Label;
            if (temp_lbActivityState.Text == "报名中")
            {
                temp_lbActivityState.ForeColor = System.Drawing.Color.FromArgb(100, 255, 102, 0);
                temp_lbActivityState.Font.Bold = true;
                temp_lblPostsCount.ForeColor = System.Drawing.Color.FromArgb(100, 255, 102, 0);
                temp_txtBeginDateTime.ForeColor = System.Drawing.Color.FromArgb(100, 255, 102, 0);
            }
            else
            {
                //temp_lbActivityState.Text = "已截止";

            }
        }
    }

    public void Reload()
    {
        IsReload = true;
        Page_Load(null, null);
    }
    /// <summary>
    /// 是否过期
    /// </summary>
    public bool IsOutOfDate { get; set; }

    /// <summary>
    /// 是否好友
    /// </summary>
    public bool IsFriend { get; set; }

    /// <summary>
    /// 是否分页
    /// </summary>
    public bool IsPaging { get; set; }

    private bool IsReload { get; set; }




}
